let a = [| 1 ; 3 ; 18 ; 5 |]

let print_array a =
  print_string "[| ";
  for i = 0 to Array.length a - 1 do
    print_int a.(i);
    print_char ' ';
  done;
  print_endline "|]";
;;

let print_matrix m =
  for i = 0 to Array.length m - 1 do
    print_array m.(i);
  done
;;

print_string "a = ";;
print_array a;;

print_string "length a = ";;
print_int (Array.length a);;
print_newline ();;

print_string "set a 1 12 = ";;
let () = Array.set a 1 12;;
print_endline "()";;

print_string "get a 1 = ";;
print_int (Array.get a 1);;
print_newline ();;

print_string "make 7 101 = ";;
print_array (Array.make 7 101);;

print_string "init 5 (fun i -> i * i) = ";;
print_array (Array.init 5 (fun i -> i * i));;

print_endline "make_matrix 3 5 42 = ";;
print_matrix (Array.make_matrix 3 5 42);;

print_string "append a a = ";;
print_array (Array.append a a);;

print_string "concat [ a ; [| 0 |] ; a ] = ";;
print_array (Array.concat [ a ; [| 0|] ; a ]);;

print_string "sub a 1 2 = ";;
print_array (Array.sub a 1 2);;

print_string "copy a = ";;
print_array (Array.copy a);;

print_string "fill a 1 2 88 = ";;
let () = Array.fill a 1 2 88 in
print_endline "()";;

print_string "a = ";;
print_array a;;

print_string "blit [| 8 ; 2 ; 7 ; 5 |] 0 a 1 3 = ";;
let () = Array.blit [| 8 ; 2 ; 7 ; 5 |] 0 a 1 3 in
print_endline "()";;

print_string "a = ";;
print_array a;;

print_string "to_list a = ";;
let () = List.iter (fun i -> print_int i; print_char ' ') (Array.to_list a);;
print_newline ();;

print_string "of_list [ 1 ; 3 ; 5 ] = ";;
print_array (Array.of_list [ 1 ; 3 ; 5 ]);;

print_string "iter print_int a = ";;
let () = Array.iter print_int a;;
print_newline ();;

print_string "map succ a = ";;
print_array (Array.map succ a);;

print_string "iteri (fun i x -> print_int i; print_int x) a = ";;
let () = Array.iteri (fun i x -> print_int i; print_int x) a;;
print_newline ();;

print_string "mapi (+) a = ";;
print_array (Array.mapi (+) a);;

print_string "fold_left (+) 0 a = ";;
print_int (Array.fold_left (+) 0 a);;
print_newline ();;

print_string "fold_right (+) a 0 = ";;
print_int (Array.fold_right (+) a 0);;
print_newline ();;

print_string "sort compare a = ";;
let () = Array.sort compare a;;
print_endline "()";;

print_string "a = ";;
print_array a;;

print_string "unsafe_set a 2 88 = ";;
let () = Array.unsafe_set a 2 88;;
print_endline "()";;

print_string "unsafe_get a 2 = ";;
print_int (Array.unsafe_get a 2);;
print_newline ();;

